package com.crm.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.crm.dao.FinanceSchoolExpendMapper;
import com.crm.model.FinanceSchoolExpend;
import com.crm.model.SysUser;
import com.crm.service.FinanceSchoolExpendService;
import com.crm.util.SessionModel;
import com.crm.util.SessionUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
public class FinanceSchoolExpendServiceImpl extends BaseServiceImpl<FinanceSchoolExpend> implements FinanceSchoolExpendService{
	@Autowired
	private FinanceSchoolExpendMapper  expendMapper;
	@Override
	public int insert(FinanceSchoolExpend record) {
		record.setSchoolExpendId(UUID.randomUUID().toString());
		return super.insert(record);
	}
	
	@Override
	public int updateByPrimaryKey(FinanceSchoolExpend record) {
		SysUser sysUser =((SysUser)SessionUtils.get(SessionModel.SESSION_USER));
		record.setModifyDate(new Date());
		record.setModifyUserId(sysUser.getUserId());
		record.setModifyUserName(sysUser.getRealName());
		return super.updateByPrimaryKey(record);
	}

	@Override
	public int getApplyTimesByUserId(String userId) {
		return expendMapper.getApplyTimesByUserId(userId);
	}
	
	@Override
	public List<FinanceSchoolExpend> selectAllByWhere(Page<FinanceSchoolExpend> page,FinanceSchoolExpend financeSchoolExpend) {
		PageHelper.startPage(page.getPageNum(), page.getPageSize(), "fse.create_date desc");
		return expendMapper.selectAllByWhere(financeSchoolExpend);
	}

	@Override
	public int getTotalMoneyByWhere(FinanceSchoolExpend financeSchoolExpend) {
		return expendMapper.getTotalMoneyByWhere(financeSchoolExpend);
	}

}
